package de.lianowar.whereismymoney.adapter;

import java.util.ArrayList;

import de.lianowar.whereismymoney.R;
import de.lianowar.whereismymoney.sql.data.MoneyAmount;

import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class DetailListAdapter extends BaseAdapter {

	private Activity context;
	private ArrayList<MoneyAmount> money;
	
    public DetailListAdapter(Activity context, ArrayList<MoneyAmount> pMoneyAmount){
        this.context=context;
        money=pMoneyAmount;
    }
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return money.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return money.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return money.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
			View element;
	        if (convertView == null)
	        {
	         LayoutInflater inflater = context.getLayoutInflater();
	         element = inflater.inflate(R.layout.row_layout, null);
	        }
	        else element = convertView;
	        Log.e("GET_VIEW", money.toString());
	        Log.e("GET_VIEW", "Position"+position);
	        if(money != null)
	        {
		        ((TextView)element.findViewById(R.id.tvDate)).setText(money.get(position).getDate());    
		        ((TextView)element.findViewById(R.id.tvComment)).setText(money.get(position).getComment());
		        ((TextView)element.findViewById(R.id.tvAmount)).setText(""+money.get(position).getAmount()+"€");
		        Button test  =(Button)element.findViewById(R.id.buDelRow);
		        test.setOnClickListener(new View.OnClickListener()
				{
					@Override
						public void onClick(View view)
						{		
							
						}
					});
	        }
	        return element;
	}
	public void changeData(ArrayList<MoneyAmount> pData){
		this.money = pData;
        this.notifyDataSetChanged();
}
}
